// 这是通过appTool自动生成的rpcx代码，请勿修改
package exampleRpc

import (
	"context"
	"errors"

	"gitee.com/kinwyb/appTools/appTool/code-generate/example/rpcx/exampleRpcObj"
	"gitee.com/kinwyb/appTools/examples/src/assembly"
	"gitee.com/kinwyb/godb"
	"github.com/smallnest/rpcx/client"
)

type arithRpcxClient struct {
	client client.XClient
}

func (a *arithRpcxClient) Init(client client.XClient) {
	a.client = client
}
func (a *arithRpcxClient) ServicePath() string {
	return "arithSev"
}

// Mul 线程
// service.go Arith
func (a *arithRpcxClient) Mul(a1 int, b1 int) (int, error) {
	var err error
	rpcxXClientCallReq := &exampleRpcObj.RpcxRequestArithMul{A1: a1, B1: b1}
	rpcxXClientCallResp := &exampleRpcObj.RpcxResponseArithMul{}
	err = a.client.Call(context.Background(), "Mul", rpcxXClientCallReq, rpcxXClientCallResp)
	if err != nil {
		if lg != nil {
			lg.Errorf("[service - Arith.Mul]RPC调用错误:%s", err.Error())
		}
		rpcxXClientCallResp.Err = errors.New("rpc服务错误")
	}
	return rpcxXClientCallResp.I, rpcxXClientCallResp.Err
}

// PageTest service.go Arith
func (a *arithRpcxClient) PageTest(d int, pg *godb.PageObj, ctx assembly.Context) []int {
	var err error
	defer ctx.Start("ArithRpcxClient.PageTest").Finish()
	rpcxXClientCallReq := &exampleRpcObj.RpcxRequestArithPageTest{D: d, Pg: pg}
	rpcxXClientCallResp := &exampleRpcObj.RpcxResponseArithPageTest{}
	err = a.client.Call(ctx.RpcxCtx(), "PageTest", rpcxXClientCallReq, rpcxXClientCallResp)
	if err != nil {
		if lg != nil {
			lg.Errorf("[service - Arith.PageTest]RPC调用错误:%s", err.Error())
		}
	}
	if pg != nil && rpcxXClientCallResp.RequestPageArg != nil {
		pg.SetTotal(rpcxXClientCallResp.RequestPageArg.Total)
	}
	return rpcxXClientCallResp.S
}

// PageTestNoResult service.go Arith
func (a *arithRpcxClient) PageTestNoResult(d int, pg *godb.PageObj, ctx assembly.Context) map[string]interface{} {
	var err error
	defer ctx.Start("ArithRpcxClient.PageTestNoResult").Finish()
	rpcxXClientCallReq := &exampleRpcObj.RpcxRequestArithPageTestNoResult{D: d, Pg: pg}
	rpcxXClientCallResp := &exampleRpcObj.RpcxResponseArithPageTestNoResult{}
	err = a.client.Call(ctx.RpcxCtx(), "PageTestNoResult", rpcxXClientCallReq, rpcxXClientCallResp)
	if err != nil {
		if lg != nil {
			lg.Errorf("[service - Arith.PageTestNoResult]RPC调用错误:%s", err.Error())
		}
	}
	if pg != nil && rpcxXClientCallResp.RequestPageArg != nil {
		pg.SetTotal(rpcxXClientCallResp.RequestPageArg.Total)
	}
	return rpcxXClientCallResp.M
}

// TestContext service.go Arith
func (a *arithRpcxClient) TestContext(ctx assembly.Context) {
	var err error
	defer ctx.Start("ArithRpcxClient.TestContext").Finish()
	err = a.client.Call(ctx.RpcxCtx(), "TestContext", nil, nil)
	if err != nil {
		if lg != nil {
			lg.Errorf("[service - Arith.TestContext]RPC调用错误:%s", err.Error())
		}
	}
	return
}

// ArithMulFun service.go
func ArithMulFun(a1 int, b1 int) int {
	var err error
	rpcxXClientCallReq := &exampleRpcObj.RpcxRequestArithMulFun{A1: a1, B1: b1}
	rpcxXClientCallResp := &exampleRpcObj.RpcxResponseArithMulFun{}
	if gClient == nil {
		err = errors.New("gClient尚未初始化")
	} else {
		err = gClient.Call(context.Background(), "ArithMulFun", rpcxXClientCallReq, rpcxXClientCallResp)
	}
	if err != nil {
		if lg != nil {
			lg.Errorf("[service - .ArithMulFun]RPC调用错误:%s", err.Error())
		}
	}
	return rpcxXClientCallResp.I
}

// NoResult service.go
func NoResult() {
	var err error
	if gClient == nil {
		err = errors.New("gClient尚未初始化")
	} else {
		err = gClient.Call(context.Background(), "NoResult", nil, nil)
	}
	if err != nil {
		if lg != nil {
			lg.Errorf("[service - .NoResult]RPC调用错误:%s", err.Error())
		}
	}
	return
}

// GoFunc service.go
func GoFunc() {
	var err error
	if gClient == nil {
		err = errors.New("gClient尚未初始化")
	} else {
		err = gClient.Call(context.Background(), "GoFunc", nil, nil)
	}
	if err != nil {
		if lg != nil {
			lg.Errorf("[service - .GoFunc]RPC调用错误:%s", err.Error())
		}
	}
	return
}

// PageTest service.go
func PageTest(pg *godb.PageObj, ctx assembly.Context) {
	var err error
	defer ctx.Start("exampleRpc.PageTest").Finish()
	rpcxXClientCallReq := &exampleRpcObj.RpcxRequestPageTest{Pg: pg}
	rpcxXClientCallResp := &exampleRpcObj.RpcxResponsePageTest{}
	if gClient == nil {
		err = errors.New("gClient尚未初始化")
	} else {
		err = gClient.Call(ctx.RpcxCtx(), "PageTest", rpcxXClientCallReq, rpcxXClientCallResp)
	}
	if err != nil {
		if lg != nil {
			lg.Errorf("[service - .PageTest]RPC调用错误:%s", err.Error())
		}
	}
	if pg != nil && rpcxXClientCallResp.RequestPageArg != nil {
		pg.SetTotal(rpcxXClientCallResp.RequestPageArg.Total)
	}
	return
}
